<template>
    <div class='approval'>
      <el-card class="box-card">
        <div class='title'>
          {{$t('achievements.title1')}}
        </div>
        <div class='menu-search'> 
            <div class='menu-title'>
                <!-- 电销人员 -->
                <div class='searchItem'>
                    <span>{{$t('ElectricChannel.ElectricPerson')}}</span>
                    <el-input v-model='listQuery.collectorName' :placeholder="$t('rule.inp')" size='small'></el-input>
                </div>
                <!-- 选择日期 -->
                <div class='searchItem searchItem-date'>
                    <span>{{$t('realTimeData.choiceDate')}}</span>
                    <el-date-picker
                    size='small'
                    v-model="listQuery.startDate"
                    type="date"
                    :placeholder="$t('rule.beginDate')"
                    value-format="yyyy-MM-dd">
                    </el-date-picker>
                    <b>{{$t('approval.go')}}</b>
                    <el-date-picker
                    size='small'
                      v-model="listQuery.endDate"
                      type="date"
                      :placeholder="$t('rule.endDate')"
                      value-format="yyyy-MM-dd">
                    </el-date-picker>
                </div>
                <!-- APP渠道 -->
                <div class='searchItem'>
                    <span>{{$t('ElectricChannel.AppChannel')}}</span>
                    <el-select v-model='listQuery.channel' size='small'>
                          <el-option
                          v-for='item in appChannel'
                          :key='item.channel'
                          :label='item.org_name'
                          :value='item.channel'>
                          </el-option>
                      </el-select>
                </div>
            </div>
            <div class='menu-title-btn'>
                <button type='button' @click='search'>
                    {{$t('btn.query')}}
                </button>
                <button type='button' @click='reset'>
                    {{$t('btn.reset')}}
                </button>
            </div>
        </div>
      </el-card>
        <el-card class='box-card' style="margin-top: 10px;margin-bottom: 20px;">
          <div class='title'>
              {{$t('ElectricChannel.dataList')}}
          </div>
          <el-table
              v-loading="listLoading"
              ref='multipleTable'
              :data='tableData'
              tooltip-effect='dark'
              style='width: 100%; margin-top: 5px;'
              @selection-change='handleSelectionChange'
              border
              size='mini'>
              <!-- 电销人员名称 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='collectorName'
              :label="$t('ElectricChannel.electricName')"
              width="120">
              </el-table-column>
              <!-- 点击量 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='clickNo'
              :label="$t('ElectricChannel.Clicks')">
              </el-table-column>
              <!-- 安装量 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='installNo'
              :label="$t('ElectricChannel.installs')">
              </el-table-column>
              <!-- 注册量 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='registerNo'
              :label="$t('ElectricChannel.registrations')">
              </el-table-column>
              <!-- 申请量 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='applyNo'
              :label="$t('ElectricChannel.applyNum')">
              </el-table-column>
              <!-- 放款量 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='loanNo'
              :label="$t('ElectricChannel.loanNum')">
              </el-table-column>
              <!-- 逾期(1-7天) -->
              <el-table-column
              header-align='center'
              align='center'
              prop='odOneToSeven'
              :label="$t('ElectricChannel.overdue1')"
              width="160">
              </el-table-column>
              <!-- 逾期(8-15天) -->
              <el-table-column
              header-align='center'
              align='center'
              prop='odEightToFifteen'
              :label="$t('ElectricChannel.overdue2')"
              width="160">
              </el-table-column>
              <!-- 逾期(16-30天) -->
              <el-table-column
              header-align='center'
              align='center'
              prop='odSixteenToThirty'
              :label="$t('ElectricChannel.overdue3')"
              width="160">
              </el-table-column>
              <!-- 逾期30天以上 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='odMoreThirty'
              :label="$t('ElectricChannel.overdue4')"
              width="160">
              </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listQuery.page"
            :page-sizes="[10, 30, 50, 100]"
            :page-size="listQuery.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
          </div>
        </el-card>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getChannels } from "api/customQuery/index";
import { getSpreadPage } from "api/channelManager/index";
export default {
  data() {
    return {
      listLoading: false,
      total: null,
      listQuery: {
        limit: 10,
        page: 1,
        collectorName: '',
        startDate: '',
        endDate: '',
        channel: ''
      },
      tableData: [],
      multipleSelection: [],
      appChannel: []
    };
  },
  created() {
    if (this.electricPinPage.has(this.$route.path)) {
      this.listQuery = this.electricPinPage.get(this.$route.path);
    }
    // 渠道下拉
    getChannels().then(res => {
      this.appChannel = res.data;
      this.listQuery.channel = this.appChannel[0].channel;
      this.getList();
    });
  },
  computed: {
    ...mapGetters(["elements", "electricPinPage"])
  },
  methods: {
    getList() {
      this.listLoading = true;
      this.$store.dispatch("saveElectriPinPage", {
        path: this.$route.path,
        listQuery: this.listQuery
      });
      getSpreadPage(this.listQuery).then(res => {
        if (res.status === 200) {
          this.listLoading = false;
          this.tableData = res.data.rows;
          this.total = Number(res.data.total);
        }
      });
    },
    //查询
    search() {
      this.listQuery.page = 1;
      this.getList();
    },
    //重置
    reset() {
      this.listQuery.limit = 10;
      this.listQuery.page = 1;
      this.listQuery.startDate = "";
      this.listQuery.endDate = "";
      this.listQuery.collectorName = "";
      this.listQuery.channel = this.appChannel[0].channel;
    },
    //选中的数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
  }
};
</script>

<style scoped lang='scss'>
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
      width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
</style>